import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//解决vue路由重复导航错误
//获取原型对象上的push函数
// const originalPush = VueRouter.prototype.push
// //修改原型对象中的push方法
// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import(/* webpackChunkName: "home" */ '@/pages/home/index.vue')
  },
  {
    path: '/question',
    name: 'question',
    component: () => import(/* webpackChunkName: "question" */ '@/pages/question/index.vue')
  },
  {
    path: '/activityRules',
    name: 'activityRules',
    component: () =>
      import(/* webpackChunkName: "ActivityRules" */ '@/pages/activityRules/index.vue')
  },
  {
    path: '/award',
    name: 'award',
    component: () => import(/* webpackChunkName: "award" */ '@/pages/award/index.vue')
  },
  {
    path: '/test',
    name: 'test',
    component: () => import(/* webpackChunkName: "test" */ '@/views/test/index.vue')
  }
]

const router = new VueRouter({
  base: '/webView',
  routes,
  mode: 'history' // history 模式 会去掉 url 中的 # 号
})

// 拦截器
router.beforeEach((to, from, next) => {
  // ...
  console.log(to.fullPath)
  next()
})

export default router
